package com.xiaoshuidi.cloud.module.report.xxljob;

import com.xiaoshuidi.cloud.framework.tenant.core.aop.TenantIgnore;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;

/**
 * 收入明细处理 job 每天凌晨3:20跑一次
 * 需将汇总明细的数据进行再次汇总统计到月
 */
@Component
@Slf4j
public class IncomeDetailDayOnceJob {

    @Resource
    private IncomeDetailDayHandleJob incomeDetailDayHandleJob;
    @Resource
    private IncomeDetailJob incomeDetailHandleJob;
    @Resource
    private CollectInAdvanceHandleJob inAdvanceHandleJob;

    @XxlJob("incomeDetailDayOnceJob")
    @TenantIgnore
    public void execute() {
        String params = XxlJobHelper.getJobParam();
        if(StringUtils.isNotBlank(params)){
            String[] split = params.split(",");
            int start = Integer.parseInt(split[0]);
            int end = Integer.parseInt(split[1]);
            for ( ; start <= end; end--) {
                LocalDate localDate = LocalDate.now().minusDays(end);
                incomeDetailDayHandleJob.execute();
                incomeDetailHandleJob.execute();
                inAdvanceHandleJob.execute();
//                System.out.println("=================="+localDate);
            }
        }


    }



}